
In this tutorial, we will learn How to Create, Delete and modify database table Column in SQL server database?
After creating a new table, you may need to add new columns to your existing table, and sometimes you may need to delete or rename the existing column, Let's see how we can do that
Add new column in existing table
minimal syntax is:
ALTER TABLE table_name ADD column_name column_datatype;
You can also add multiple column at the same time syntax is:
ALTER TABLE table_name
ADD (column_1 column_datarype,
column_2 column_datatype,
...
column_n column_datatype);
Example:
Use abctutorial /*Use Your_database_name*/
ALTER TABLE Users ADD UserPassword nvarchar(50);
Rename the existing column
minimal syntax is:
EXEC sp_rename 'table_name.old_column', 'new_name', 'COLUMN';
Example:
Use abctutorial /*Use Your_database_name*/
EXEC sp_rename 'Users.UserPassword', 'UserPwd', 'COLUMN';
Delete the existing column
minimal syntax is:
ALTER TABLE table_name
DROP COLUMN column_name;
Example:
Use abctutorial /*Use Your_database_name*/
ALTER TABLE Users
DROP COLUMN UserPwd;